<?php
require_once('include/My/DbHelper.php');

class UserHelper
{
    public static function getEmailUsersByRole($roleId)
    {
        $sql = "SELECT u.id as user_id, ea.email_address as email FROM acl_roles_users aru
                INNER JOIN users u ON u.id = aru.user_id
                INNER JOIN email_addr_bean_rel eabr ON eabr.bean_id = u.id AND bean_module = 'Users' AND eabr.primary_address = 1
                INNER JOIN email_addresses ea ON eabr.email_address_id = ea.id
                WHERE role_id = '". $roleId ."' and aru.deleted = 0
                AND u.deleted = 0 AND u.status = 'Active' AND ea.deleted = 0";
        
        return DbHelper::fetchPairs($sql, 'user_id', 'email');
    }
    
    public static function getUsersEmail()
    {
        $sql = "SELECT u.id as user_id, ea.email_address as email 
                FROM  users u 
                INNER JOIN email_addr_bean_rel eabr ON eabr.bean_id = u.id AND bean_module = 'Users' AND eabr.primary_address = 1
                INNER JOIN email_addresses ea ON eabr.email_address_id = ea.id
                WHERE u.deleted = 0 AND u.status = 'Active' AND ea.deleted = 0";
        
        return DbHelper::fetchPairs($sql, 'user_id', 'email');
    }
}